import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

def send_email(smtp_config, recipients, subject, body):
    msg = MIMEMultipart()
    msg['From'] = smtp_config['sender_email']
    msg['To'] = recipients
    msg['Subject'] = subject
    msg.attach(MIMEText(body, 'html'))
    try:
        server = smtplib.SMTP(smtp_config['server'], int(smtp_config['port']))
        server.starttls()
        server.login(smtp_config['username'], smtp_config['password'])
        text = msg.as_string()
        server.sendmail(smtp_config['sender_email'], recipients.split(','), text)
        server.quit()
        print(f"邮件已成功发送给: {recipients}")
        return True
    except Exception as e:
        print(f"发送邮件时出错: {e}")
        return False 